package cn.org.atool.fluent.mybatis.metadata.feature;

import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

import static cn.org.atool.fluent.mybatis.metadata.feature.EscapeExpress.NONE_ESCAPE;
import static cn.org.atool.fluent.mybatis.metadata.feature.PagedFormat.UN_SUPPORT_LIMIT;

/**
 * 数据库特性
 *
 * @author darui.wu
 */
@SuppressWarnings("unused")
@Data
@Accessors(chain = true)
@ToString
public class DbFeature {
    private String name;

    private String desc;

    private String driver;
    /**
     * 数据库链接url开头部分
     */
    private String urlPrefix = "not set";

    private EscapeExpress escape;

    private PagedFormat paged;

    private String seq;
    /**
     * 固定schema名称
     */
    private String fixSchema;

    private boolean before = false;
    /**
     * 是否内存数据库
     */
    private boolean isMemory = false;

    public DbFeature(String name, String desc) {
        this.name = name;
        this.desc = desc;
        this.escape = NONE_ESCAPE;
        this.paged = UN_SUPPORT_LIMIT;
    }

    public DbFeature(String name, PagedFormat paged) {
        this.name = name;
        this.desc = name;
        this.escape = NONE_ESCAPE;
        this.paged = paged;
    }

    public String getPagedFormat() {
        return this.paged.getFormat();
    }

    /**
     * 拷贝特性设置
     *
     * @return DbFeature
     */
    public DbFeature copy() {
        return new DbFeature(this.name, this.desc)
            .setDriver(this.driver)
            .setEscape(this.escape)
            .setPaged(this.paged)
            .setSeq(this.seq)
            .setBefore(this.before)
            .setMemory(this.isMemory)
            .setFixSchema(this.fixSchema);
    }
}